tree grammar BlocksTreeGrammar;

options {
  ASTLabelType = CommonTree; 
  output       = template;
}

// Tokens used internally by Moca
// ID: ('a'..'z' | 'A'..'Z')+;
// STRING: ( ID | ('0'..'9') )+; 
// ATRIBUTE: Used as an imaginary token for coding attributes in XML files (ATTRIBUTE name=ID value=STRING)
tokens {
  ID;
  STRING;
  ATTRIBUTE; 
} 
  
@header {
package org.moflon.moca.blocks.unparser;
}
// tree grammar rules:
main: ^(SPEC ^(BLOCKS b+=block+) ^(MAPPINGS m+=mapping+))
  -> specification(block={$b}, mapping={$m});

block: ^(name=STRING ports+=STRING+)
  -> block(name={$name}, ports={$ports});

mapping: ^(from=STRING to=STRING)
  -> mapping(from={$from}, to={$to});